<?php
/**
 * Created by viva.
 * User: xj
 * Tel:  13675170078
 * Date: 2015/6/9
 * Time: 14:30
 */
namespace Admin\Controller;
class NewsController extends CommonController
{
    public  function newsList()
    {
        $newsModel=M('News');
        $this->assign('news',$newsModel->select());
        $this->display();
    }

    public function edit()
    {
        $id = I('id');
        if ($id) {
            $News = M('News');
            $result = $News->where(array('id' => $id))->find();
            $this->assign('news', $result);
        }
        $this->display();
    }
    public function add()
    {
        $this->display();
    }
    public function update()
    {
        $NavAdModel = M('News');
        $NavAdModel->create();
        if ($_FILES['img']['size'] != 0) {
            $file = new FileController();
            $img_info = $file->upload('news_img');
            $NavAdModel->img = $img_info['img']['savepath'] . $img_info['img']['savename'];
        }
        $NavAdModel->start_time = strtotime(I('start_time'));
        $NavAdModel->end_time = strtotime(I('end_time'));
        if (!I('id'))
            $NavAdModel->add();
        else
            $NavAdModel->save();

        $this->success('编辑成功');
    }

    public function remove()
    {
        $id=I('id');
        if($id)
        {
            $NavAd=M('News');
            $NavAd->delete($id);
        }
    }
}